# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gsasl
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.0
pkgrel=2
pkgdesc="Simple Authentication and Security Layer framework and a few common SASL mechanisms (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://josefsson.org/gsasl/"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-winpthreads"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "gtk-doc")
options=('strip' 'staticlibs')
depends=("${MINGW_PACKAGE_PREFIX}-gss"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-libntlm"
         "${MINGW_PACKAGE_PREFIX}-readline")
validpgpkeys=('B1D2BD1375BECB784CF4F8C4D73CF638C53C06BE'   # Simon Josefsson <simon@josefsson.org>
              '9AA9BDB11BB1B99A21285A330664A76954265E8C')  # Simon Josefsson <simon@josefsson.org>
source=(https://ftp.gnu.org/gnu/gsasl/${_realname}-${pkgver}.tar.gz{,.sig}
        "0001-gsasl-avoid-conflicting-types.patch"
        "0002-automake-gltests-add-pthread.patch")
sha256sums=('85bcbd8ee6095ade7870263a28ebcb8832f541ea7393975494926015c07568d3'
            'SKIP'
            '6d321e0d0ad49a1b6022f2b139f88fd17eb48af314e96dc50ccb228f255c8732'
            '80517301b1d2514465cd4c3a7d564761e4544465a4be44bd56f6da22dcac63be')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i "${srcdir}/0001-gsasl-avoid-conflicting-types.patch"
  patch -p1 -i "${srcdir}/0002-automake-gltests-add-pthread.patch"

  # autoreconf to get updated libtool files with clang support.
  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-kerberos_v5

  # Without -j1, make error No rule to make target libgsasl-7.def.
  make -j1
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
